package com.core.thread;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @author lxf
 * @date 2018/7/5 11:33
 * To change this template use Editor | File and Code Templates.
 */
public class ThreadSortTest {

    static class Thread1 extends Thread {
        @Override
        public void run() {
            System.out.println("t1 执行了," + Thread.currentThread().getName());
        }
    }

    static class Thread2 extends Thread {
        @Override
        public void run() {
            System.out.println("t2 执行了," + Thread.currentThread().getName());
        }
    }

    static class Thread3 extends Thread {
        @Override
        public void run() {
            System.out.println("t3 执行了," + Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        Thread1 t1 = new Thread1();
        Thread2 t2 = new Thread2();
        Thread3 t3 = new Thread3();

        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("demo-pool-%d").build();
        ExecutorService pool = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
        pool.submit(t1);
        pool.submit(t2);
        pool.submit(t3);
        pool.shutdown();

    }

}
